package com.thoughtworks.studio.tools.cardkit;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Map;

import org.apache.log4j.Logger;

import com.thoughtworks.studio.tools.cardkit.parser.CardParser;
import com.thoughtworks.studio.tools.cardkit.parser.ParserException;

public class CardRepository {
	private static Logger logger = Logger.getLogger(CardManager.class);
	private CardParser cardParser;
	private String cardsroucefilename;
	private Map<Float, Card> cards = null;

	public CardParser getCardParser() {
		return cardParser;
	}

	public Map<Float, Card> getCards() {
		if (cards == null) {
			try {
				cardParser.parse(cardsroucefilename);
				cards = cardParser.getCards();
			} catch (FileNotFoundException e) {
				logger.warn("can not find the file "+ cardsroucefilename);
			} catch (IOException e) {
				logger.warn("can not read the file "+ cardsroucefilename);
			} catch (ParserException e) {
				logger.warn("Can not parse the file "+ cardsroucefilename);
				e.printStackTrace();
			}
		}
		return cards;
	}

	public void setCards(Map<Float, Card> cards) {
		this.cards = cards;
	}

	public CardParser getParser() {
		return cardParser;
	}
	

	public void setCardParser(CardParser cardParser) {
		this.cardParser = cardParser;
	}

	public void setCardsroucefilename(String cardsroucefilename) {
		this.cardsroucefilename = cardsroucefilename;
	}

	public String getCardsroucefilename() {
		return cardsroucefilename;
	}
}
